package Scrap;

import java.util.Scanner;

public class Maze {

	int m, n, sr, sc;
	boolean found = false;
	char maze[][];

	Maze(int tm, int tn) {
		m = tm;
		n = tn;
		maze = new char[m][n];
	}

	public static void main(String args[]) throws Exception {
		Scanner in = new Scanner(System.in);
//		Maze mm = new Maze(in.readInt(), in.readInt());
//		mm.readInput(in);
//	mm.print();
//		mm.process(mm.sr, mm.sc, 1, 0);
	}

	void readInput(
	//		SimpleInput in
			) throws Exception {

//		for (int i = 0; i < m; i++)
//			for (int j = 0; j < n; j++) {
//				in.skipWhite();
//				maze[i][j] = in.readChar();
//				if (maze[i][j] == '#') {
//					sr = i;
//					sc = j;
//				}
//			}

	}

	void process(int cr, int cc, int di, int hop) {

		System.out.println(maze[cr][cc] + " " + cr + " " + cc + " " + m + " "
				+ n);
		if (cr >= 0 && cr < m && cc >= 0 && cc < n) {
			if (maze[cr][cc] == '@') {
				found = true;
				System.out.println("Here is the hops : " + hop);
			}
			if (maze[cr][cc] != '1' && maze[cr][cc] != '#')
				return;
			else
				maze[cr][cc] = 0;

			while (found == false) {
				System.out.print(maze[cr][cc] + " " + di + " ");
				if (di == 1) {
					process(cr - 1, cc, di, hop + 1);
					System.out.print("returns ");
					di = 3;
					System.out.print("heres di : " + di);
				} else if (di == 3) {
					process(cr + 1, cc, di, hop + 1);
					di = 2;
				} else if (di == 2) {
					process(cr, cc + 1, di, hop + 1);
					di = 4;
				} else if (di == 4) {
					process(cr, cc - 1, di, hop + 1);
					di = 1;
				}
			}
		}
	}

	void print() {

		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++)
				System.out.print(maze[i][j] + " ");
			System.out.println();
		}
	}

}
